<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>登录-奥莱购管理系统</title>
    <script src="./js/jquery.1.11.3.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="./css/bootstrap.min.css">
    <script src="./js/axios.js"></script>
    <script src="./js/cookie.js"></script>
    <style>
        body,
        html {
            height: 100%;
            background: #F1F2F3;
        }
    </style>
</head>

<body>

    <div class="container">
        <div class="row">
            <div class="col-xs-3"></div>
            <div class="col-xs-6">
                <h1 class="">奥莱购管理系统 <a href=""><span class="brand-name">CMS</span></a></h1>

                <div class="form">
                    <div id="username-field" class="field-wrapper input">
                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                            stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
                            class="feather feather-user">
                            <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path>
                            <circle cx="12" cy="7" r="4"></circle>
                        </svg>
                        <input id="username" name="username" type="text" class="form-control" placeholder="请输入您的用户名"
                            value="zqszqszqs">
                    </div>

                    <div id="password-field" class="field-wrapper input mb-2">
                        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor"
                            stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
                            class="feather feather-lock">
                            <rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect>
                            <path d="M7 11V7a5 5 0 0 1 10 0v4"></path>
                        </svg>
                        <input id="password" name="password" type="password" class="form-control" placeholder="请输入您的密码"
                            value="zqszqszqs">
                    </div>
                    <div class="d-sm-flex justify-content-between">
                        <input type="checkbox" class="new-control-input" id="check_ed">7天免登录
                        <span id="remind" class="pull-right" style="color: crimson;"></span><br>
                        <input type="submit" class="btn btn-primary" value="登录" id="login"><br><br>
                    </div>
                </div>

                <p class="terms-conditions">© 2020 All Rights <a href="">千峰H5-2008>>郑秋爽</a></p>
            </div>
            <div class="col-xs-3"></div>

        </div>
    </div>
    <script>
        $(function () {
            //如果之前存过，取出来放到文本框里
            if (getCookie("username")) {
                $("#username").val(getCookie("username"));
                $("#password").val(getCookie("password"));
                $("#check_ed").prop("checked", true);
            }
            //判断登录是否成功
            $("#login").click(function () {
                axios.get(
                    `http://jx.xuzhixiang.top/ap/api/login.php?username=${$("#username").val()}&password=${$("#password").val()}`
                ).then(res => {
                    console.log(res.data);
                    if (res.data.code == 1) {
                        console.log("登陆成功");
                        let uid = res.data.data.id
                        let token = res.data.data.token
                        console.log(uid, token);
                        if ($("#check_ed").is(':checked')) {
                            setCookie("username", $("#username").val(), 7);
                            setCookie("password", $("#password").val(), 7);
                            setCookie("uid", uid, 7);
                            setCookie("token", token, 7);
                        } else {
                            setCookie("username", $("#username").val());
                            setCookie("password", $("#password").val());
                            setCookie("uid", uid);
                            setCookie("token", token);
                        }
                        $(location).attr('href', "cms_index.html");
                    } else {
                        $("#remind").text("登陆失败,请检查您的用户名和密码");
                    }


                })
            })
        })
    </script>
</body>

</html>